<?php
/*
 * inc-author.php
 * Retral/CSCD494 Winter 2009
 * Eastern Washington University
 *
 * File Description:
 * Shows the exams and questions authored by a user. The user is selected
 * by the REQUEST parameter "id"
 * 
 * Other:
 * 
 */
 ?>
<span class="header-text">Author Profile</span><br>

<?php
$conn = oci_connect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);

$ID = $_REQUEST['id'];

$query = '
     SELECT ape_user.first_name, ape_user.last_name
     FROM ape_user WHERE user_id=:ID';
$stmt = oci_parse($conn, $query);
oci_bind_by_name($stmt, ':ID', $ID);
if(!oci_execute($stmt))
	print "<P>Could not find author requested</P>";

$result = oci_fetch_assoc($stmt); 

print "<h2>".$result['LAST_NAME'].", ".$result['FIRST_NAME']."</h2>";

oci_free_statement($stmt);

$query = '
	SELECT question_id FROM question
	INNER JOIN question_content 
	ON question.question_content_id=question_content.question_content_id
	WHERE author_id=:ID';

$stmt = oci_parse($conn, $query);
oci_bind_by_name($stmt, ':ID', $ID);
if(!oci_execute($stmt))
	print "<P>Could not find author questions</P>";

echo "<h3>Authored Questions</h3>\n";
while($row = oci_fetch_assoc($stmt)) {
	echo "<a href='?page=question&id=".$row['QUESTION_ID']."'>";
	echo $row['QUESTION_ID']."</a><br>\n";
}

oci_free_statement($stmt);

$query = '
	SELECT exam_id FROM exam
	WHERE author_id=:ID';

$stmt = oci_parse($conn, $query);
oci_bind_by_name($stmt, ':ID', $ID);
if(!oci_execute($stmt))
	print "<P>Could not find author exams<P>";

echo "<h3>Authored Exams</h3>\n";
while($row = oci_fetch_assoc($stmt)) {
	echo "<a href='?page=preview&exam=".$row['EXAM_ID']."'>";
	echo $row['EXAM_ID']."<br>\n";
}

oci_free_statement($stmt);
?>
